package testenv.model.entity;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.Parameter;

import testenv.model.AbstractBaseEntity;


@Entity
@SequenceGenerator(name="structure_id_seq", sequenceName="structure_id_sequence")
@FilterDef(name="versionFilter", parameters={
		@ParamDef(name="version", type="string")
})
@NamedQuery(name="structure.orderByStructureName", query="SELECT s FROM Structure s WHERE s.id = :id ORDER BY s.structureName")
public class Structure extends AbstractBaseEntity {
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="structure_id_seq")
	@GenericGenerator(
	     name="structure_id_seq",
	     strategy="sequence",
	     parameters= {
	         @Parameter(name="minvalue", value="1"),
	         @Parameter(name="increment", value="1"),
	         @Parameter(name="sequence", value="structure_id_sequence")
	     })
	private Integer id = null;
	
	@Column(nullable=false, length=50)
	private String structureName = null;
	
	@OneToMany(mappedBy="structure", cascade=CascadeType.ALL)
	@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	@Filter(name="versionFilter", condition=":version like version")
	private Set<StructureVersion> structureVersion = new HashSet<StructureVersion>();
	
	@OneToMany(cascade=CascadeType.ALL)
	@Cascade(value={
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN,
			org.hibernate.annotations.CascadeType.ALL}
	)
	@JoinColumn(name="structure_id", nullable=false)
	@IndexColumn(name="position", base=0, nullable=false)
	private List<ElementGroup> elementGroupList = new ArrayList<ElementGroup>(); 
	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getStructureName() {
		return structureName;
	}

	public void setStructureName(String structureName) {
		this.structureName = structureName;
	}

	public Set<StructureVersion> getStructureVersion() {
		return structureVersion;
	}

	public void setStructureVersion(Set<StructureVersion> structureVersion) {
		this.structureVersion = structureVersion;
	}

	public List<ElementGroup> getElementGroupList() {
		return elementGroupList;
	}

	public void setElementGroupSet(List<ElementGroup> elementGroupList) {
		this.elementGroupList = elementGroupList;
	}
	
	
}
